﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using MovieRental.Entities;

namespace MovieRental.EfRepositoryLibrary.Mappers
{
    public class EditionMapper : BaseMapper<EditionInfo, Guid, Edition, Edition, MovieRentalEntitiesContainer>
    {
        public override void Convert(EditionInfo entity, Edition model)
        {
            model.Id = entity.Id;
            model.MediaTypeId = entity.MediaTypeId;
            model.MovieId = entity.MovieId;
            if (entity.DiscountId == Guid.Empty)
                model.TemporaryDiscountId = null;
            else
                model.TemporaryDiscountId = entity.DiscountId;
            model.Publisher = entity.Publisher;
            model.Quantity = entity.Quantity;
            model.PricePerDay = entity.PricePerDay;
        }

        public override void ConvertBack(Edition model, EditionInfo entity)
        {
            entity.Id = model.Id;
            entity.MediaTypeId = model.MediaTypeId;
            entity.MovieId = model.MovieId;
            if (model.TemporaryDiscountId == null)
                entity.DiscountId = Guid.Empty;
            else
                entity.DiscountId = model.TemporaryDiscountId.Value;
            entity.Publisher = model.Publisher;
            entity.Quantity = model.Quantity;
            entity.PricePerDay = model.PricePerDay;
        }

        public override Guid SelectKey(Edition model)
        {
            return model.Id;
        }

        public override Guid SelectKey(EditionInfo entity)
        {
            return entity.Id;
        }

        public override ObjectSet<Edition> SelectObjectSet(MovieRentalEntitiesContainer context)
        {
            return context.Editions;
        }
    }
}
